#ifndef __SCNS_TJPGDEC_H__
#define __SCNS_TJPGDEC_H__

#include "ScnsConfig.h"

#if defined(SCNS_TJPGDEC_ENABLE)&&SCNS_TJPGDEC_ENABLE==1

#include "ScnsYing.h"
#include "ScnsColor.h"
#include <string.h>


typedef struct ScnsTjpgdec ScnsTjpgdec;

struct ScnsTjpgdec
{
    ScnsSize dctr;                                    /* Number of bytes available in the input buffer */
    uint8*dptr;                                     /* Current data read ptr */
    uint8*inbuf;                                    /* Bit stream input buffer */
    uint8 dbit;                                     /* Number of bits availavble in wreg or reading bit mask */
    uint8 msx,msy;                                  /* MCU size in unit of block (width, height) */
    uint8 qtid[3];                                  /* Quantization table ID of each component, Y, Cb, Cr */
    uint8 ncomp;                                    /* Number of color components 1:grayscale, 3:color */
    int16 dcv[3];                                   /* Previous DC element of each component */
    uint16 nrst;                                    /* Restart inverval */
    uint16 width,height;                            /* Size of the input image (pixel) */
    uint8*huffbits[2][2];                           /* Huffman bit distribution tables [id][dcac] */
    uint16*huffcode[2][2];                          /* Huffman code word tables [id][dcac] */
    uint8*huffdata[2][2];                           /* Huffman decoded data tables [id][dcac] */
    int32*qttbl[4];                                 /* Dequantizer tables [id] */
    uint32 wreg;                                    /* Working shift register */
    uint8 marker;                                   /* Detected marker (0:None) */
    void*workbuf;                                   /* Working buffer for IDCT and RGB output */
    int16*mcubuf;                                   /* Working buffer for the MCU */
    ScnsSize (*infunc)(ScnsTjpgdec*,uint8*,ScnsSize);   /* Pointer to jpeg stream input function */
    void*device;                                    /* Pointer to I/O device identifiler for the session */
};

extern ScnsStatus scnsTjpgdecPrepare(ScnsTjpgdec*jd,ScnsSize (*infunc)(ScnsTjpgdec*,uint8_t*,ScnsSize),void*dev);
extern ScnsStatus scnsTjpgdecDecomp(ScnsTjpgdec*jd,ScnsStatus (*outfunc)(ScnsTjpgdec*,ScnsColorArgb8888*,Point plu,uint16 w,uint16 h));
extern void scnsTjpgdecFree(ScnsTjpgdec*jd);
#if defined(SCNS_LCD_ENABLE)&&SCNS_LCD_ENABLE==1

#include "ScnsLcd.h"

extern void scnsLcdDisplayJpgImage(ScnsLcdLayer layN,Point plu,const void*p,uint32 pSize,int16 disW,int16 disH,uint8 merge);

#endif

#endif
#endif
